package com.example.demo.commom;

import lombok.Data;
import org.springframework.web.bind.annotation.ControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-03-31
 * Time:18:43
 */
@Data
public class AjaxResult  {
    //状态码
    private Integer code;
    //状态码错误
    private String msg;
    //返回数据
    private Object data;

    /*
    数据返回成功
     */
    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        ajaxResult.setCode(200);
        ajaxResult.setMsg("");
        return ajaxResult;
    }
    public static AjaxResult success(Integer code,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        ajaxResult.setCode(code);
        ajaxResult.setMsg("");
        return ajaxResult;
    }
    public static AjaxResult success(String msg,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        ajaxResult.setCode(200);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    public static AjaxResult success(Integer code,String msg,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    /*
    返回失败
     */
    public static AjaxResult fail(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(-1);
        ajaxResult.setMsg("");
        ajaxResult.setData("");
        return ajaxResult;
    }
    public static AjaxResult fail(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(-1);
        ajaxResult.setMsg(msg);
        ajaxResult.setData("");
        return ajaxResult;
    }
    public static AjaxResult fail(Integer code,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg("");
        ajaxResult.setData("");
        return ajaxResult;
    }
    public static AjaxResult fail(String msg,Integer code) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData("");
        return ajaxResult;
    }


}
